import datetime

from sqlalchemy import Column, Integer, String, Float, DateTime, UniqueConstraint

from QualityInspectionViolation.DbInit.mysqlDb import Base, session
from QualityInspectionViolation.Model.Adviser import Adviser


class RoleMenu(Base):
    __tablename__ = 'role_menu'
    id = Column(Integer, primary_key=True)
    roleId = Column(Integer)
    menuId = Column(Integer)
    createdAt = Column(DateTime, default=datetime.datetime.now)
    updatedAt = Column(DateTime, default=datetime.datetime.now)

    def queryRoleMenu(self, adviserId):
        roleMenu = session.query(RoleMenu).join(Adviser, Adviser.roleId == RoleMenu.roleId).filter(Adviser.id == adviserId).filter(RoleMenu.menuId == 21).first()

        print("roleMenu：", roleMenu)
        return roleMenu

    def queryRoleMenuByRoleId(self, roleId, menuId, session):
        roleMenu = session.query(RoleMenu).filter(RoleMenu.menuId == menuId).filter(RoleMenu.roleId == roleId).first()

        print("roleMenu：", roleMenu)
        return roleMenu

    def insertRoleMenu(self, roleMenu, session):
        session.add(roleMenu)

    def deleteRoleMenu(self, roleMenuId, session):
        session.query(RoleMenu).filter(RoleMenu.id == roleMenuId).delete()